//
//  YTAccountMoneyViewController.m
//  YiTuDriverClient
//
//  Created by 石少庸 on 2017/5/19.
//  Copyright © 2017年 Yitu. All rights reserved.
//

#import "YTAccountMoneyViewController.h"
#import "YTWithdrawViewController.h"
#import "YTUserProfileServices.h"

@interface YTAccountMoneyViewController ()
@property (weak, nonatomic) IBOutlet UILabel *sumText;
@property (weak, nonatomic) IBOutlet UILabel *depositText;
@property (weak, nonatomic) IBOutlet UIButton *depositBtn;
@property (weak, nonatomic) IBOutlet UILabel *unCheckText;
@property (weak, nonatomic) IBOutlet UILabel *cashDepositText;
@end

@implementation YTAccountMoneyViewController

- (void)initialize {
    [SVProgressHUD show];
    [[YTUserProfileServices laodUserFinance] subscribeNext:^(NSDictionary *response) {
        [SVProgressHUD dismiss];
        NSDictionary *dataDict = response[@"responseData"];
        if ([dataDict[@"allMoney"] floatValue] != 0.0) {
            self.sumText.text = [NSString stringWithFormat:@"%.2f", [dataDict[@"allMoney"] floatValue]];
        }
        
        if ([dataDict[@"remain"] floatValue] != 0.0) {
            self.depositText.text = [NSString stringWithFormat:@"%.2f", [dataDict[@"remain"] floatValue]];
            [self.depositBtn setBackgroundColor:kMainBlueColor];
            self.depositBtn.enabled = YES;
        }
        
        if ([dataDict[@"unsettled"] floatValue] != 0.0) {
            self.unCheckText.text = [NSString stringWithFormat:@"%.2f", [dataDict[@"unsettled"] floatValue]];
        }
        
        if ([dataDict[@"earnestMoney"] floatValue] != 0.0) {
            self.cashDepositText.text = [NSString stringWithFormat:@"%.2f", [dataDict[@"earnestMoney"] floatValue]];
        }
    }];
}

/// 提现，这里需要先判断有没有设置提现密码，然后判断是否绑定了账号
- (IBAction)embodyAction:(UIButton *)sender {
    if ([YTUtilityManager manager].userModel.hasPayPassword == 1) {
        // 如果没有账号，则提示去添加
        if ([YTUtilityManager manager].userModel.accountCount == 0) {
            [UIAlertView bk_showAlertViewWithTitle:@"友情提示" message:@"您还未添加提现账户"
                                 cancelButtonTitle:@"知道了" otherButtonTitles:@[@"立即添加"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
                                     [self performSegueWithIdentifier:@"YTWithdrawAction" sender:nil];
                                 }];
            return;
        }
        [self performSegueWithIdentifier:@"YTWithdraw" sender:nil];
    } else {
        [self performSegueWithIdentifier:@"YTSetEmbody" sender:nil];
    }
}

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"YTWithdraw"]) {
        YTWithdrawViewController *withdraw = segue.destinationViewController;
        withdraw.moneyNum = self.depositText.text;
    }
}

@end
